package com.gdones.bootserver.bus.paraminfo.controller;


import com.gdones.bootserver.bus.paraminfo.dto.ParamInfo;
import com.gdones.bootserver.bus.paraminfo.service.IParamInfoService;
import com.gdones.common.core.annotations.MySysLog;
import com.gdones.common.core.annotations.MySysLogOpration;
import com.gdones.common.core.dto.MyPageBand;
import com.gdones.common.core.dto.MyResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 字典数据操作接口
 *
 * @author GaoJingBo
 * @since 2023-03-27
 */
@RestController
@RequestMapping("/sys/paraminfo")
@Api(tags={"字典表-字典数据操作接口"})
@Slf4j
public class ParamInfoController {

    @Resource(name = "paramInfoServiceImpl")
    private IParamInfoService paramInfoService;

    /**
     * 字典表-项目分页查询
     * @param paramInfo 查询条件
     * @param page 分页参数
     * @return
     */
    @GetMapping("/pages")
    @ApiOperation("字典表-项目分页查询")
    @MySysLog(modelName="字典表-数据管理",methodDesc = "项目分页查询",methodType = MySysLogOpration.GET)
    public MyResult getParamInfoPage(ParamInfo paramInfo, MyPageBand page){
        log.info("--- 字典管理：字典表-项目分页查询");

        MyResult result = new MyResult();
        try{
            result = paramInfoService.getParamInfoPage(paramInfo,page);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("字典表-项目分页系统异常");
            result.setCode("9999");
        }

        return result;
    }

    /**
     * 字典管理：添加字典项目
     * @param paramInfo 字典项目数据
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("字典表-项目:添加字典项目")
    @MySysLog(modelName="字典表-数据管理",methodDesc = "添加字典项目",methodType = MySysLogOpration.POST)
    public MyResult addParamInfo(@RequestBody ParamInfo paramInfo){
        log.info("--- 字典管理：添加字典项目");

        MyResult result = new MyResult();
        try{
            result = paramInfoService.add(paramInfo);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("添加字典项目系统异常");
            result.setCode("9999");
        }

        return result;
    }

    /**
     * 字典管理：修改字典项目
     * @param paramInfo 字典项目数据
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("字典表-项目:修改字典项目")
    @MySysLog(modelName="字典表-数据管理",methodDesc = "修改字典项目",methodType = MySysLogOpration.PUT)
    public MyResult updateParamInfo(@RequestBody ParamInfo paramInfo){
        log.info("--- 字典管理：修改字典项目");

        MyResult result = new MyResult();
        try{
            result = paramInfoService.update(paramInfo);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("修改字典项目系统异常");
            result.setCode("9999");
        }

        return result;
    }

    /**
     * 字典管理：删除字典项目
     * @param paramInfoIDs 要删除的id，多个用逗号分隔
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation("字典表-项目:删除字典项目")
    @MySysLog(modelName="字典表-数据管理",methodDesc = "删除字典项目",methodType = MySysLogOpration.DELETE)
    public MyResult deleteParamInfo(String paramInfoIDs){
        log.info("--- 字典管理：修改字典项目");

        MyResult result = new MyResult();
        try{
            Object paramInfo;
            result = paramInfoService.delete(paramInfoIDs);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("删除字典项目系统异常");
            result.setCode("9999");
        }

        return result;
    }

}
